<!doctype html>
<html ng-app="app">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../../build/common/base.css" rel="stylesheet">
<script type="text/javascript" src="../../build/common/base.js"></script>
<script type="text/javascript" src="../../build/common/ngEdit.js"></script>
</head>
<script type="text/javascript">
	var id = $.getParam("id");
	var app = angular.module('app', [ 'baseDirective' ]);
	app.controller("ctrl", [ '$scope', 'baseService','ArrayToolService', 
		function($scope, baseService,ArrayToolService) {
			$scope.ArrayTool = ArrayToolService;
			$scope.isSaveEd = id;
			if(id){
				/* $("#name").attr("readonly","readonly");
				$(".typeInput").attr("disabled","disabled");
				$("#typeText").hide(); */
			}else{
				/* $scope.data.type='1'; */
				/* $("#typeRadio").hide(); */
			}
			/**
			 * 数据初始化。
			 */
			$scope.init=function(){
				if(!$scope.data){
					$scope.data={};
				}
			};
			
			$scope.selectProductRelation = function(){
				if(!$scope.data){
		 			$scope.data={};
		 		}
		 		if(!$scope.data.customerRelationList){
		 			$scope.data.customerRelationList = [];
		 		}
		 		var arr = [];
		 		var newList = [];
				for(var i=0,relation;relation = $scope.data.customerRelationList[i++];){
					if(relation.type == "customerProduct"){
						var object = {};
						object.id = relation.productId;
						object.name = relation.productName;
						arr.push(object);
					}else{
						newList.push(relation);
					}
				}
		 		
		 		CustUtil.openCustDialog("productSelector",function(data,innerWindow){
					$scope.$apply(function(){
						$scope.data.customerRelationList = newList;
						
						//将重新选择的放入到List中
						for(var i = 0; i < data.length; i++) {
							var rights = {
								type :"customerProduct",
								productId: data[i].id,
								productName : data[i].name,
								};
							$scope.data.customerRelationList.push(rights);
						}
						});
				   $.Dialog.close(innerWindow);
				},arr);
		 	}
			
			$scope.selectPossesserList = function(){
		 		if(!$scope.data.possesserList){
		 			$scope.data.possesserList = [];
		 		}
		 		var arr = [];
		 		var newList = [];
				for(var i=0,possesser;possesser = $scope.data.possesserList[i++];){
					var object = {};
					object.id = possesser.id;
					object.fullname = possesser.fullname;
					arr.push(object);
				}
		 		
		 		CustUtil.openCustDialog("userSingleSelector",function(data,innerWindow){
					$scope.$apply(function(){
						$scope.data.possesserList = newList;
						
						//将重新选择的放入到List中
						for(var i = 0; i < data.length; i++) {
							var rights = {
								userId : data[i].id,
								fullname : data[i].fullname,
								};
							$scope.data.possesserList.push(rights);
						}
						});
				   $.Dialog.close(innerWindow);
				},arr);
		 	}
			
			} ]);

	/* 获取URL表单的 JSON 数据  必须以 getData为方法名*/
	function getData() {
		return AngularUtil.getScope().data;
	}
	/* 获取URL表单的校验情况，必须以isValid 为方法名 */
	function isValid() {
		//校验表单 ab-validate的 校验
		if (!ngUtil.getScope().form.$valid) {
			$.Dialog.error("表单校验不通过！");
			return false;
		}

		// 您可以自由的去做特殊业务逻辑的校验
		/* if (!ngUtil.getScope().data.name) {
			$.Dialog.error("产品名称不可为空！");
			return false;
		}
		return true; */
	}
</script>
<body class="panel success" ng-controller="ctrl">
	<!-- 顶部按钮 -->
	<div class="panel-heading" >
		<a class="btn btn-primary fa-save" ng-model="data"
			ab-save="/crm/customer/save"> 保存 </a> <a href="javascript:void(0)"
			class="btn btn-sm btn-primary fa-reply"
			onclick="javascript:$.Dialog.close(window);"> 返回 </a>
	</div>
	<!--  ab-load 去controller 层获取业务数据  -->
	<form name="form" method="post" ab-load="crm/customer/get?id={id}"
		ng-model="data">

		<table class="form-table">
			<tbody>
				<tr class="firstRow">
					<th>客户名称</th>
					<td><input type="text" class=" form-control"
						ng-model="data.name" id="name" ng-disabled="data.id!=null"  
						desc="客户名称" ab-validate="{&quot;required&quot;:true}" /></td>
				</tr>
				<tr ng-show="data.id!=null">
					<th >类型</th>
					<td>
						<!-- <div ng-model="data.type" 
							ab-validate="{}" desc="类型">
							<label class=" radio-inline"><input type="radio" class="typeInput" ng-disabled="true"  
								ng-model="data.type" value="0" />个人客户</label><label
								class=" radio-inline"><input type="radio" class="typeInput" ng-disabled="true"
								ng-model="data.type" value="1" />公海客户</label>
						</div> -->
						<span ng-if="data.type==0">个人客户</span>
						<span ng-if="data.type==1">公海客户</span>
					</td>
				</tr>
				<!-- <tr>
					<th>
						<span>所有者</span>
						<span class="required">*</span>
					</th>
					<td>
						<span ng-repeat="possesser in data.possesserList" style="margin-right: 10px" class="label label-danger"> {{possesser.fullname}}
						<button href="javascript:void(0)" class="btn btn-link btn-default btn-xs" ng-click="ArrayTool.remove(possesser,data.possesserList)">×</button></span>
						<span class="btn  btn-sm btn-primary fa fa-search" ng-click="selectPossesserList()">选择</span> 
					</td>
				</tr> -->
			
				<tr>
					<th>公司地址</th>
					<td><textarea type="text" class=" form-control"
							ng-model="data.address"
							desc="公司地址" ab-validate="{}"></textarea></td>
				</tr>
				<tr>
					<th>行业</th>
					<td><input type="text" class=" form-control"
						ng-model="data.industry" 
						desc="行业" ab-validate="{}" /></td>
				</tr>
				<tr>
					<th>公司网址</th>
					<td><input type="text" class=" form-control"
						ng-model="data.website"
						desc="公司网址" ab-validate="{}" /></td>
				</tr>
				<tr>
					<th>微信公众号</th>
					<td><input type="text" class=" form-control"
						ng-model="data.wechatOfficialAccount"
						desc="微信公众号" ab-validate="{}" /></td>
				</tr>
				<tr>
					<th>联系人姓名</th>
					<td><input type="text" class=" form-control"
						ng-model="data.contactName"
						desc="联系人姓名" ab-validate="{}" /></td>
				</tr>
				<tr>
					<th>联系人生日</th>
					<td><input class=" form-control"
						ng-model="data.contactBirthday" ab-validate="{}"
						desc="联系人生日"
						ab-date="yyyy-MM-dd" /></td>
				</tr>
				<tr>
					<th>联系人职务</th>
					<td><input type="text" class=" form-control"
						ng-model="data.contactPosition"
						desc="联系人职务" ab-validate="{}" /></td>
				</tr>
				<tr>
					<th>联系人电话</th>
					<td><input type="text" class=" form-control"
						ng-model="data.contactNumber"
						desc="联系人电话" ab-validate="{}" /></td>
				</tr>
				<tr>
					<th>传真号码</th>
					<td><input type="text" class=" form-control"
						ng-model="data.faxNumber"
						desc="传真号码" ab-validate="{}" /></td>
				</tr>
				<tr>
					<th>电子邮件</th>
					<td><input type="text" class=" form-control"
						ng-model="data.email"
						desc="电子邮件" ab-validate="{}" /></td>
				</tr>
				<tr>
					<th>客户状态</th>
					<td><span type="text" class=" input-div"
						ng-model="data.state" ab-validate="{}" desc="客户状态"
						ab-combox="data.state" dict-key="khzt"></span></td>
				</tr>
				<tr>
					<th>客户级别</th>
					<td><span type="text" class=" input-div"
						ng-model="data.level" ab-validate="{}" desc="客户级别"
						ab-combox="data.level" dict-key="khjb"></span></td>
				</tr>
				<tr>
					<th>成熟度</th>
					<td><span type="text" class=" input-div"
						ng-model="data.maturity" ab-validate="{}" desc="成熟度"
						ab-combox="data.maturity" dict-key="khcsd"></span> 
					</td>
				</tr>
				<tr>
					<th>客户来源</th>
					<td><span type="text" class=" input-div"
						ng-model="data.source" ab-validate="{}" desc="客户来源"
						ab-combox="data.source" dict-key="khly"></span></td>
				</tr>
				<tr>
					<th>主营项目</th>
					<td><input type="text" class=" form-control"
						ng-model="data.mainProject"
						desc="主营项目" ab-validate="{}" /></td>
				</tr>
				<tr>
					<th>备注</th>
					<td><textarea type="text" class=" form-control"
							ng-model="data.remark"
							desc="备注" ab-validate="{}"></textarea></td>
				</tr>
				<!-- <tr>
					<th>最后跟进时间</th>
					<td><input class=" form-control"
						ng-model="data.lastFollowupTime" ab-validate="{}"
						desc="最后跟进时间"
						ab-date="yyyy-MM-dd HH:mm:ss" /></td>
				</tr> -->
				<!-- <tr>
					<th>类型</th>
					<td><div ng-model="data.type"
							ab-validate="{}" desc="类型">
							<label class=" radio-inline"><input type="radio"
								ng-model="data.type" value="0" />个人客户</label><label
								class=" radio-inline"><input type="radio"
								ng-model="data.type" value="1" />公海客户</label>
						</div></td>
				</tr> -->
				
				<tr>
					<th>
						<span>意向产品:</span>
					</th>
					<td>
						<span ng-repeat="relation in data.customerRelationList |filter:{type:'customerProduct'}" style="margin-right: 10px" class="label label-danger"> {{relation.productName}}
						<button href="javascript:void(0)" class="btn btn-link btn-default btn-xs" ng-click="ArrayTool.remove(relation,data.customerRelationList)">×</button></span>
						<span class="btn  btn-sm btn-primary fa fa-search" ng-click="selectProductRelation()">选择</span> 
					</td>
				</tr>
			</tbody>
		</table>
	</form>
</body>
</html>